<template>
	<el-container class="main_container">
		<!-- 头部 -->
		<el-header>
			<div>
				<img src="@/assets/photo.jpeg" alt />
				<span>小阿基CRM后台管理系统</span>
			</div>
			<el-button type="info" @click="logout">退出</el-button>
		</el-header>
		<!-- 主体 -->
		<el-container class="sub_container">
			<!-- 侧边栏 -->
			<el-aside :width="isCollapse ? '64px' : '200px'">
				<div class="toggle-button" @click="togleCollapse">
					<i class="el-icon-s-fold" v-show="!isCollapse"></i>
					<i class="el-icon-s-unfold" v-show="isCollapse"></i>
				</div>
				<el-menu unique-opened :collapse="isCollapse" :collapse-transition="false" router :default-active="activePath"
				 background-color="#333744" text-color="#fff" active-text-color="#409FFF">
					<!-- 一级菜单  -->
					<el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
						<!-- 一级菜单的模板区域 -->
						<template slot="title">
							<i class="el-icon-menu"></i>
							<span>{{ item.authName}}</span>
						</template>
						<!-- 二级菜单 -->
						<el-menu-item :index="'' + subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="changePath('' + subItem.path)">
							<!-- 二级菜单的模板区域 -->
							<template slot="title">
								<i class="el-icon-s-tools"></i>
								<span>{{ subItem.authName}}</span>
							</template>
						</el-menu-item>
					</el-submenu>
				</el-menu>
			</el-aside>
			<!-- 内容主体 -->
			<el-main>
				<router-view></router-view>
			</el-main>
		</el-container>
	</el-container>
</template>
<script>
	export default {
		data() {
			return {
				// 左侧菜单数据
				menuList: [{
					id: '1000',
					authName: '日常管理',
					children: [{
							id: '1001',
							authName: '欢迎页',
							path: '/welcome'
						},
						{
							id: '1002',
							authName: '员工列表',
							path: '/emplist'
						},
						{
							id: '1003',
							authName: '测试功能',
							path: '/demolab'
						}
					]
				}],
				// 默认不折叠
				isCollapse: false,
				// 被激活导航地址
				activePath: ''
			}
		},
		created() {
			// this.getMenuList()
			this.activePath = window.sessionStorage.getItem('activePath') ? window.sessionStorage.getItem('activePath') :
				'/welcome'
		},
		methods: {
			logout() { //注销
				// 清空token
				window.sessionStorage.clear()
				this.$router.push('/login')
			},
			// 菜单的折叠与展开
			togleCollapse() {
				this.isCollapse = !this.isCollapse
			},
			// 切换页面地址
			changePath(activePath) {
				this.activePath = activePath
				window.sessionStorage.setItem('activePath', activePath)
			}
		}
	}
</script>
<style lang="less" scoped>
	.main_container {
		width: 100%;
		height: 100vh;
		
		.sub_container {
			width: 100%;
			height: calc(100vh - 60px)!important;
			
			.el-aside {
				height: 100%;
				background-color: #333744;
			
				.el-menu {
					border: none;
				}
			}
			
			.el-main {
				height: 100%;
				background-color: #eaedf1;
			}
		}
	}

	.el-header {
		background-color: #373f41;
		display: flex;
		justify-content: space-between;
		padding-left: 20px;
		align-items: center;
		color: #fff;
		font-size: 20px;

		>div {
			display: flex;
			align-items: center;

			img {
				height: 40px;
				width: 40px;
			}

			span {
				margin-left: 15px;
			}
		}
	}

	.iconfont {
		margin-right: 10px;
	}

	.toggle-button {
		background-color: #4A5064;
		font-size: 20px;
		line-height: 30px;
		color: #fff;
		text-align: center;
		letter-spacing: 0.2em;
		cursor: pointer;
	}
</style>
